 
const app = getApp()

Page({
  data: {
    SearchName:"",
    config: app.globalData.config,
    page: {
      searchCount: false,
      current: 1,
      size: 10,
    },
    name:'',
    curIndex: 0,
    loadmore: true,
    cateList: [],
    intern: [],
    swiperData: [
      '../../public/my/1.jpg',
      '../../public/my/2.jpg',
      '../../public/my/3.jpg',
    ],
    cardCur: 0,
    noticeData: [], 
    userInfo:''

  }, 
  onShow(){
    // 默认登录
    app.initPage().then(res => {
      this.setData({
        userInfo: res,
        intern: []
      })
      console.log(res)
      this.getWishCate()
      this.getWorkPage(true)
    })
  },
  onLoad() {
  },
  toDetail(e){
    if(this.data.userInfo.auths == 0){
      wx.showModal({
        title: '提示',
        showCancel: false,
        content: '此功能仅对星程计划学员开放，详细请咨询【启航星程SV小助手】（微信号：starvoyage01）',
        complete: (res) => { 
        }
      })
      return
    }
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: `/pages/wish/wishDetail/index?id=${id}`,
    })
  },
  // 获取实习
  getWorkPage(isClear) {
    // if(isClear){
    //   this.setData({
    //     intern: []
    //   })
    // }
    app.api.getWorkPage({
      searchCount: false,
      current: this.data.page.current,
      size: this.data.page.size,
      cateId: this.data.curIndex == 0 ? ''  
              : this.data.cateList[this.data.curIndex].id,
      title: this.data.SearchName
      // descs: 'create_time'
    })
      .then(res => { 
        let intern = res.data.records
        this.setData({
          intern: [...this.data.intern, ...intern]
        })
      })
  }, 
  onChange(e){
    this.setData({
        SearchName: e.detail
    })
  },
  // 搜索
  onClick(){
    this.setData({intern:[]})
    this.setData({
      ['page.current']: 1,
      cateId:'',
      intern:[]
    })
    this.getWorkPage()
  },
  onShareAppMessage: function () {
    let title = '启航星程StarVoyage'
    let path = 'pages/home/index'
    return {
      title: title,
      path: path,
      success: function (res) {
        if (res.errMsg == 'shareAppMessage:ok') {
          console.log(res.errMsg)
        }
      },
      fail: function (res) {
        // 转发失败
      }
    }
  },
  // 切换tab
  cateSwitch(e){
    this.setData({
      ['page.current']: 1,
      curIndex: e.currentTarget.dataset.index,
      intern:[]
      
    })
    this.getWorkPage()
  },
  //志愿活动分类
  getWishCate() {
    app.api.getWishCate({id:1})
      .then(res => {
          console.log(res)
        res.data.unshift({id:'',name:'全部'})
        this.setData({
          cateList: res.data
        }) 
      })
  },
  refresh(){
    this.setData({
      loadmore: true,
      ['page.current']: 1,
      goodsList: [],
    })
  },
  onPullDownRefresh(){
    // 显示顶部刷新图标
    wx.showNavigationBarLoading()
    this.refresh()
    // 隐藏导航栏加载框
    wx.hideNavigationBarLoading()
    // 停止下拉动作
    wx.stopPullDownRefresh()
  },
  onReachBottom() {
    if (this.data.loadmore) {
    }
    this.setData({
      ['page.current']: this.data.page.current + 1
    })
    this.getWorkPage()
  }, 
})
